package com.lx.exception;

public class BizException extends Exception {
    private String errorCode = "20000";
    private String showMessage;
    private Throwable cause;

    public BizException() {
    }

    public BizException(String message) {
        super(message);
    }

    public BizException(String errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
    }

    public BizException(String message, Throwable cause) {
        super(message, cause);
        this.cause = cause;
    }

    public BizException(String errorCode, String message, Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
        this.cause = cause;
    }

    public String getMessage() {
        String msg = super.getMessage();
        String causeMsg = null;
        if (this.cause != null) {
            causeMsg = this.cause.getMessage();
        }

        if (msg != null) {
            return causeMsg != null ? msg + " caused by: " + causeMsg : msg;
        } else {
            return causeMsg;
        }
    }

    public BizException(Throwable cause) {
        super(cause);
        this.cause = cause;
    }

    public String toString() {
        return this.cause == null ? super.toString() : super.toString() + " cause: " + this.cause.toString();
    }

    public String getErrorCode() {
        return this.errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getShowMessage() {
        return this.showMessage == null ? super.getMessage() : this.showMessage;
    }

    public void setShowMessage(String showMessage) {
        this.showMessage = showMessage;
    }

}
